home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 6 code / TCP / finger / CvtAddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-03  |  1.2 KB  |  49 lines  |  [TEXT/MPS ]

  1. #include <Types.h>
  2. #include <MacTCPCommonTypes.h>
  3. #include <AddressXLation.h>
  4. #include "CvtAddr.h"
  5.  
  6. pascal void DNRResultProc(struct hostInfo *hInfoPtr,char *userDataPtr);
  7.  
  8. /*    ConvertStringToAddr is a simple call to get a host's IP number, given the name
  9.     of the host.
  10. */
  11.  
  12. OSErr ConvertStringToAddr(char *name,unsigned long *netNum)
  13. {
  14.     struct hostInfo hInfo;
  15.     OSErr result;
  16.     char done = 0x00;
  17.     extern Boolean gCancel;
  18.  
  19.     if ((result = OpenResolver(nil)) == noErr) {
  20.         result = StrToAddr(name,&hInfo,DNRResultProc,&done);
  21.         if (result == cacheFault)
  22.             while (!done)
  23.                 ; /* wait for cache fault resolver to be called by interrupt */
  24.         CloseResolver();
  25.         if ((hInfo.rtnCode == noErr) || (hInfo.rtnCode == cacheFault)) {
  26.             *netNum = hInfo.addr[0];
  27.             strcpy(name,hInfo.cname);
  28.             name[strlen(name)-1] = '\0';
  29.             return noErr;
  30.         }
  31.     }
  32.     *netNum = 0;
  33.  
  34.     return result;
  35. }
  36.  
  37.  
  38. /*    This is the completion routine used for name-resolver calls.
  39.     It sets the userDataPtr flag to indicate the call has completed.
  40. */
  41.  
  42. pascal void DNRResultProc(struct hostInfo *hInfoPtr,char *userDataPtr)
  43. {
  44. #pragma unused (hInfoPtr)
  45.  
  46.     *userDataPtr = 0xff;    /* setting the use data to non-zero means we're done */
  47. }
  48.  
  49.